<?php

namespace App\Models;

use App\Models\dispatch\PlaceModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class ReturnItemModel extends BaseModel
{
    use HasFactory;

    protected $table = 't_return_item';

    protected $primaryKey = 'id';

    public $timestamps = true;

    const CREATED_AT = 'created_at';
    
    const UPDATED_AT = null;

    protected $guarded = [];

    protected $hidden = [
        'deleted_at',
    ];

    //退货状态 1退货待入库 2退货已入库 3退货已出库
    public const STATUS_WAIT_STORAGE = 1;
    public const STATUS_STORAGE = 2;
    public const STATUS_OUT_STOCK = 3;
    const STATUS_MAPS = [
        1 => '退货待入库',
        2 => '退货已入库',
        3 => '退货已出库',
    ];

    //来源 1手动登记 2问题件
    public const SOURCE_MAPS = [
        1 => '手动登记',
        2 => '问题件',
    ];


    //创建人
    public function create_admin(): BelongsTo {
        return $this->belongsTo(AdminModel::class, 'created_admin_id');
    }

    //入仓单
    public function order(): BelongsTo {
        return $this->belongsTo(OrderModel::class, 'order_id');
    }

    //库位
    public function place(): BelongsTo {
        return $this->belongsTo(PlaceModel::class, 'dispatch_place_id');
    }

    //入库人
    public function storage_admin(): BelongsTo {
        return $this->belongsTo(AdminModel::class, 'storage_admin_id');
    }

    //出库人
    public function out_stock_admin(): BelongsTo {
        return $this->belongsTo(AdminModel::class, 'out_stock_admin_id');
    }

}
